package me.zhengjie.modules.lock.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.modules.lock.service.LockDevicePwdService;
import me.zhengjie.modules.lock.service.dto.LockDeviceOfflinePwdDTO;
import me.zhengjie.modules.lock.service.vo.LockDeviceOfflinePwdVO;
import me.zhengjie.modules.lock.service.vo.LockDevicePwdListReqVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Api(tags = "密码：密码列表")
@RequestMapping("/api/v1/lock/pwd")
public class LockDevicePwdController {
    @Autowired
    private LockDevicePwdService lockDevicePwdService;

    @AnonymousAccess
    @ApiOperation("查询密码列表")
    @GetMapping(value = "/list")
    //@PreAuthorize("@el.check('pwd:list')")
    public ResponseEntity<Object> getPwdList(LockDevicePwdListReqVO pwdListReqVO, Pageable pageable) {
        return new ResponseEntity<>(lockDevicePwdService.getPwdList(pwdListReqVO, pageable), HttpStatus.OK);
    }

    @AnonymousAccess
    @ApiOperation(value = "请求离线密码接口")
    @PostMapping("/getOfflinePwd")
    //@PreAuthorize("@el.check('pwd:offline')")
    public ResponseEntity<Object> getOfflinePwd(@Valid @RequestBody LockDeviceOfflinePwdVO offlinePwdVO) {
        LockDeviceOfflinePwdDTO offlinePwdDTO = lockDevicePwdService.getOfflinePwd(offlinePwdVO);
        return new ResponseEntity<>(offlinePwdDTO, HttpStatus.OK);
    }
}
